//
//  AssetGroupViewCell.m
//  PingTu
//
//  Created by Yangfan on 15/2/4.
//  Copyright (c) 2015年 4gread. All rights reserved.
//

#import "AssetGroupViewCell.h"

@implementation AssetGroupViewCell

- (void)bind:(ALAssetsGroup *)assetsGroup {
    self.assetsGroup            = assetsGroup;
    
    CGImageRef posterImage      = assetsGroup.posterImage;
    size_t height               = CGImageGetHeight(posterImage);
    float scale                 = height / kThumbnailLength;
    
    self.imageView.image        = [UIImage imageWithCGImage:posterImage scale:scale orientation:UIImageOrientationUp];
    self.textLabel.text         = [assetsGroup valueForProperty:ALAssetsGroupPropertyName];
    self.detailTextLabel.text   = [NSString stringWithFormat:@"%ld张", (long)[assetsGroup numberOfAssets]];
    self.accessoryType          = UITableViewCellAccessoryDisclosureIndicator;
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(15, 99, self.frame.size.width - 15, 1)];
    view.backgroundColor = [UIColor colorWithRed:137.0/255.0 green:131/255.0 blue:122/255.0 alpha:1];
    [self.contentView addSubview:view];
    
    [self setAccessoryType:UITableViewCellAccessoryNone];
    
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"rightDirection"]];
    [imageView setFrame:CGRectMake(self.frame.size.width - 44, 0, 44, 99)];
    [self.contentView addSubview:imageView];
}

- (NSString *)accessibilityLabel {
    NSString *label = [self.assetsGroup valueForProperty:ALAssetsGroupPropertyName];
    return [label stringByAppendingFormat:@"%ld 张照片", (long)[self.assetsGroup numberOfAssets]];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
